/**
 * 管理初始化
 */
var OrderInfo = {
    id: "OrderInfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
OrderInfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '订单id', field: 'orderId', visible: true, align: 'center', valign: 'middle'},
            {title: '用户id', field: 'userId', visible: true, align: 'center', valign: 'middle'},
            {title: '需求类型', field: 'type', visible: true, align: 'center', valign: 'middle',
            	formatter: function (value, row, index) {
                    if (value == '0') {
                        return "买家需求";
                    }
                    if (value == '1') {
                        return "卖家需求";
                    } 
                }
            },
            {title: '小程序aappSecret', field: 'appSecret', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序appid', field: 'appid', visible: true, align: 'center', valign: 'middle'},
            {title: '买家需求id', field: 'buyerDemandId', visible: true, align: 'center', valign: 'middle'},
            {title: '卖家需求id', field: 'sellerDemandId', visible: true, align: 'center', valign: 'middle'},
            {title: '金额(圆)', field: 'amount', visible: true, align: 'center', valign: 'middle',
            	formatter: function (value, row, index) {
                     return value/100;
                  
                }	
            }, 
            {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',
            	formatter: function (value, row, index) {
                    if (value == '0') {
                        return "待支付";
                    }
                    if (value == '1') {
                        return "已支付";
                    } 
                    if (value == '2') {
                        return "支付失败";
                    }
                }	
            },
            {title: '支付时间', field: 'payTime', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'createdBy', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'gmtCreate', visible: true, align: 'center', valign: 'middle'},
            {title: '更新人', field: 'lastUpdatedBy', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'gmtLastUpdate', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
OrderInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        OrderInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
OrderInfo.openAddOrderInfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/orderInfo/orderInfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
OrderInfo.openOrderInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/orderInfo/orderInfo_update/' + OrderInfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
OrderInfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/orderInfo/delete", function (data) {
            Feng.success("删除成功!");
            OrderInfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("orderInfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
OrderInfo.search = function () { 
    var condition = {};
    condition['orderId'] = $("#orderId").val(); 
    condition['endTime'] = $("#endTime").val(); 
    condition['beginTime'] = $("#beginTime").val(); 
    condition['appid'] = $("#appid").val(); 
    OrderInfo.table.refresh({query: condition});
};

$(function () {
    var defaultColunms = OrderInfo.initColumn();
    var table = new BSTable(OrderInfo.id, "/orderInfo/list", defaultColunms);
    table.setPaginationType("server");
    OrderInfo.table = table.init();
    
    var condition = {};
    condition['orderId'] = $("#orderId").val(); 
    condition['endTime'] = $("#endTime").val(); 
    condition['beginTime'] = $("#beginTime").val(); 
    condition['appid'] = $("#appid").val(); 
    debugger
    var ajax = new $ax(Feng.ctxPath + "/orderInfo/getStatistics", function (data) { 
    	debugger
    	
    	$("#totalamount").text("订单总金额:"+data.totalamount/100);
    	$("#count").text("订单总数:"+data.count);
    }, function (data) {
        
    });
    ajax.set("orderInfo",condition);
    ajax.start();
    
    
});
